package com.rran.study.chat.common.base;

import com.rran.study.chat.common.exception.ErrorEnum;
import com.rran.study.chat.common.exception.ValidateException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

/**
 * @author yy
 * @Type BaseController.java
 * @Desc
 * @date 2020/8/11 23:34
 */
public class BaseController {

    public void checkParameters(BindingResult bindingResult){
        if (bindingResult.hasErrors()) {
            for (ObjectError object : bindingResult.getAllErrors()) {
                String message = object.getDefaultMessage();
                throw new ValidateException(ErrorEnum.BODY_NOT_MATCH.getErrorCode(),message);
            }
        }
    }
}
